const ALOss = require("@/lib/aliyun/signature/index")
const OSSObj = require('@/lib/aliyun/oss/obj')

class Server {

	constructor() {

	}

	/**
	 * 阿里云OSS签名
	 * @param data
	 * @returns {Promise<{OSSAccessKeyId: *, signature: PromiseLike<ArrayBuffer>, saveName: string, policy: string, startsWith: *}>}
	 */
	static async ossSignature (data) {
		const baseData = ALOss.init(data)
		// 首先获取总个数
		return baseData
	}

	/**
	 * 获取OSS文件列表
	 * @param ctx 环境上下文
	 * @returns {Promise<*>}
	 */
	static async ossAll (ctx) {
		const { prefix, lastKey, pageSize, bucket } = ctx.vals
		return await OSSObj.list(prefix, lastKey, pageSize, bucket)
	}

	/**
	 * 删除OSS文件
	 * @param ctx
	 * @returns {Promise<boolean>}
	 */
	static async ossRemove (ctx) {
		const { fileName, bucket } = ctx.vals
		return await OSSObj.deleteObj(fileName, bucket)
	}
}

module.exports = Server
